package cn.sdc.bugKiller.dao;

import java.util.List;

import cn.sdc.bugKiller.bean.MemberBean;

public class MemberDaoImpl extends BaseDao{
	
	/**
	 * get member by username
	 */
	public MemberBean getMemberByUsername(String username){
		String sql = "select id,username, email,password,admin_flg,create_date,default_project from m_member"
					+" where username= ?/*username*/ ";

		MemberBean bean = (MemberBean)dbutil.doSelectBean(
						MemberBean.class,
						sql,
						new Object[]{username},
						new Class[]{String.class});
		return bean;
	}
	
	public MemberBean getMemberById(Integer id){
		String sql = "select id,username, email,password,admin_flg,create_date,default_project  from m_member"
					+" where id = ?/*ID*/ ";
				;
		MemberBean bean = (MemberBean)dbutil.doSelectBean(
						MemberBean.class,
						sql,
						new Object[]{id},
						new Class[]{Integer.class});
		return bean;
	}
	
	/**
	 * select All user
	 */
	public List<MemberBean> selectAllUser(){
		String sql = "select id,username, email,password,admin_flg,create_date,default_project from m_member";
		List<MemberBean> memberList = (List<MemberBean>)dbutil.doSelectBeanList(MemberBean.class,sql);
		return memberList;
	}
	
	/*// old version
	public MemberBean getMemberByUsername(String username){
		String sql = "select id,username, email,password,admin_flg,create_date from m_member"
					+" where username='"+username+"'";
		ResultSet rs = super.dbutil.doSelect(sql);
		MemberBean bean = null;
		try {
			rs.next();
			bean = new MemberBean();
			bean.setId(rs.getLong(1));
			bean.setUsername(rs.getString(2));
			bean.setEmail(rs.getString(3));
			bean.setPassword(rs.getString(4));
			bean.setAdminFlg(rs.getInt(5)==1);
			bean.setCreateDate(rs.getDate(6));
		} catch (SQLException e) {
		}
		return bean;
	}
	
	public List<MemberBean> SelectAllUser(){
		String sql = "select id,username, email,password,admin_flg,create_date from m_member";
		List<MemberBean> memberList = new ArrayList<MemberBean>();
		ResultSet rs = super.dbutil.doSelect(sql);
		try {
			while(rs.next()){
				MemberBean bean = new MemberBean();
				bean.setId(rs.getLong(1));
				bean.setUsername(rs.getString(2));
				bean.setEmail(rs.getString(3));
				bean.setPassword(rs.getString(4));
				bean.setAdminFlg(rs.getInt(5)==1);
				bean.setCreateDate(rs.getDate(6));
				memberList.add(bean);
			}
		} catch (SQLException e) {
			
		}
		return memberList;
	}
	*/
	
	

	
}
